/* Declarations for event handling.

   This file is part of khipu.

   khipu is free software: you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public License
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */

#ifndef __KP_EVENT__
#define __KP_EVENT__   1

#include <csignal>
#include "defs.hpp"
#include "initop.hpp"

KP_DECLS_BEGIN

struct interpreter;

const int KP_NSIG = 
#ifdef NSIG
  NSIG;
#elif defined (_NSIG)
 _NSIG;
#elif defined (SIGMAX)
  SIGMAX + 1;
#elif defined (SIG_MAX)
  SIG_MAX + 1;
#elif defined (_SIGMAX)
  _SIGMAX + 1;
#else
  8 * sizeof (sigset_t) + 1;
#endif

const int THREXIT_EV = KP_NSIG + 1;
const int PROCEXIT_EV = KP_NSIG + 2;
const int GCREQ_EV = KP_NSIG + 3;

// All signals + the three above.
const int NPENDEV = KP_NSIG + 3;

// Install the event handler FCT for event EV.
object add_evhandler (interpreter *interp, unsigned int ev, object fct);

// Get the event handler for event EV.
object get_evhandler (interpreter *interp, unsigned int ev);

// Init OP for the event subsystem.
KP_EXPORT init_op init_event;

KP_DECLS_END

#endif
